package com.kjc.demo.rcservice.service;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kjc.demo.rcservice.bean.DocDownloadRecordBean;
import com.kjc.demo.rcservice.repository.DocDownloadRecordMapper;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.sdhs.paas.sdk.base.common.entity.PaginationEntity;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;

/**
* 描述：DocDownloadRecordService 服务接口
* @author kangjichang
* @date 2018-12-04
*/

@EnablePaasMybatis
@MapperScan("com.kjc.demo.rcservice.repository")
@Service
public class DocDownloadRecordService extends BaseDao<DocDownloadRecordBean, DocDownloadRecordMapper, Integer>{
		@Override
		public String getMapperNamespace() {
			return DocDownloadRecordMapper.class.getName();
		}
		
		@Autowired
		private DocDownloadRecordMapper docDownloadRecordMapper;
		
		public PaginationEntity<DocDownloadRecordBean> getPageDocDownloadRecordList(BasePage pageRequest, DocDownloadRecordBean docDownloadRecordBean) {
			Page<DocDownloadRecordBean> pageTotal = PageHelper.startPage(pageRequest.getPage(), pageRequest.getPageSize(),true);
			List<DocDownloadRecordBean> list = docDownloadRecordMapper.getList(docDownloadRecordBean);
			PaginationEntity<DocDownloadRecordBean> paginationEntity = new PaginationEntity<DocDownloadRecordBean>(list,
	                (int) pageTotal.getTotal());
			return paginationEntity;
		}
		
		@Transactional(rollbackFor = Exception.class)
		public boolean saveDocDownloadRecord(DocDownloadRecordBean docDownloadRecordBean) {
			try {
				//ucAppBean.setCtime(System.currentTimeMillis());
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = docDownloadRecordMapper.insertDocDownloadRecord(docDownloadRecordBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		@Transactional(rollbackFor = Exception.class)
		public boolean updateDocDownloadRecord(DocDownloadRecordBean docDownloadRecordBean) {
			try {
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = docDownloadRecordMapper.updateDocDownloadRecord(docDownloadRecordBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		public DocDownloadRecordBean getDocDownloadRecordDetail(String id) {
			return docDownloadRecordMapper.getDocDownloadRecordDetail(id);
		}
		
		public boolean deleteDocDownloadRecord(DocDownloadRecordBean docDownloadRecordBean){
			return docDownloadRecordMapper.deleteDocDownloadRecord(docDownloadRecordBean)>0;
		}
      
}